package org.gaaidou.ptarmigan.springboot.distributed.redis;

import org.gaaidou.ptarmigan.springboot.distributed.DistributedLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.locks.Lock;

@Component
public class RedisDistributedLock implements DistributedLock {
    @Autowired
    private RedissonClient redissonClient;

    public Lock create(String resource, int lockTimeoutSecond) {
        return new RedisLock(resource, lockTimeoutSecond, redissonClient);
    }

    public Lock create(String resource) {
        return new RedisLock(resource, 20, redissonClient);
    }
}
